<?php


namespace app\shop\controller\group;


use app\BaseController;
use app\shop\service\chat\ChatVoiceService;

class ChatVoiceController extends BaseController
{
    /**
     * 拨打电话
     * @return \think\response\Json
     */
    public function call()
    {
        try {
            $chatSign = $this->request->param('chat_sign', '', 'trim');
            $userInfo = $this->request->middleware('userInfo');
            $chatVoiceService = new ChatVoiceService();
            $msgId = $chatVoiceService->call($chatSign, $userInfo);
            return $this->success($msgId);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 接通
     * @return \think\response\Json
     */
    public function accept()
    {
        try {
            $msgId = $this->request->param('msg_id', 0, 'int');
            $userInfo = $this->request->middleware('userInfo');
            $chatVoiceService = new ChatVoiceService();
            $result = $chatVoiceService->accept($msgId, $userInfo);
            return $this->success($result);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 拒绝接通
     * @return \think\response\Json
     */
    public function refuse()
    {
        try {
            $msgId = $this->request->param('msg_id', 0, 'int');
            $userInfo = $this->request->middleware('userInfo');
            $chatVoiceService = new ChatVoiceService();
            $chatVoiceService->refuse($msgId, $userInfo);
            return $this->success();
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 挂断
     * @return \think\response\Json
     */
    public function hangup()
    {
        try {
            $msgId = $this->request->param('msg_id', 0, 'int');
            $userInfo = $this->request->middleware('userInfo');
            $chatVoiceService = new ChatVoiceService();
            $chatVoiceService->hangup($msgId, $userInfo);
            return $this->success();
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 正在通话的用户
     * @return \think\response\Json
     */
    public function getVideoGroupUser()
    {
        try {
            $chatSign = $this->request->param('chat_sign', '', 'trim');
            $chatVoiceService = new ChatVoiceService();
            $userList = $chatVoiceService->getVideoGroupUser($chatSign);
            return $this->success($userList);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }
}